package com.ymatou.iapi.trading.operate.service;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;

/**
 * 发货效验接口Call FreeMaker Template自动生成代码
 */
public class DeliveryValidationCall extends YmatouBaseCall {
    private static String opurl = "api/Seller/DeliveryValidation";

    public DeliveryValidationCall() {
        super(EnvSetup.getSystemUrl("operate_iapi"), opurl, "POST", "JSON");
    }

    @Override
    public void addDefHeader() {
        client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
        client.addHeader("Content-Type", "application/json; charset=UTF-8");
    }

    // get data
    public JSONObject getData() {
        JSONObject data = null;
        try {
            data = new JSONObject(getReturnData()).getJSONObject("data");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return data;
    }

    // get getDeliveryValidationResults
    public ArrayList<JsonDeliveryValidationResult> getDeliveryValidationResults() {
        ArrayList<JsonDeliveryValidationResult> resutlList = new ArrayList<JsonDeliveryValidationResult>();
        Gson gson = new Gson();
        try {
            resutlList = gson.fromJson(getData().getString("validateDeliveryResultList"),
                    new TypeToken<ArrayList<JsonDeliveryValidationResult>>() {
                    }.getType());
        } catch (JsonSyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return resutlList;
    }

    public class JsonDeliveryValidationResult {
        int orderId;
        
        int buyerId;

        boolean isCanDelivery;

        String resultMsg;

        String address;

        String recipient;

        String phone;

        String telephone;

        String postCode;

        public int getBuyerId() {
            return buyerId;
        }

        public void setBuyerId(int buyerId) {
        	buyerId = buyerId;
        }

        public int getResultCode() {
            return resultcode;
        }

        public void setResultCode(int resultCode) {
            resultcode = resultCode;
        }

        String email;
        
        int  resultcode;

        public int getOrderId() {
            return orderId;
        }

        public void setOrderId(int orderId) {
        	orderId = orderId;
        }

        public boolean getIsCanDelivery() {
            return isCanDelivery;
        }

        public void setIsCanDelivery(boolean isCanDelivery) {
        	isCanDelivery = isCanDelivery;
        }

        public String getResultMsg() {
            return resultMsg;
        }

        public void setResultMsg(String resultMsg) {
        	resultMsg = resultMsg;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            address = address;
        }

        public String getRecipient() {
            return recipient;
        }

        public void setRecipient(String recipient) {
            recipient = recipient;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            phone = phone;
        }

        public String getTelephone() {
            return telephone;
        }

        public void setTelephone(String telephone) {
            telephone = telephone;
        }

        public String getPostCode() {
            return postCode;
        }

        public void setPostCode(String postCode) {
        	postCode = postCode;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            email = email;
        }
        
    }

}